<%-- 
    Document   : home.jsp
    Created on : 16/03/2012, 10:57:20 AM
    Author     : John
--%>

<%@page import="riteservices.model.bean.Rating"%>
<%@page import="riteservices.util.Constantes"%>
<%@page import="riteservices.model.bean.Request"%>
<%@page import="java.util.List"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="riteservices.model.bean.Notification"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Date"%>
<%@page import="riteservices.model.bean.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Home :: YoTeLlevo.Com</title>
        
     
         <link rel="stylesheet" type="text/css" href="public/bootstrap/css/bootstrap-responsive.css" />
         <link rel="stylesheet" type="text/css" href="public/bootstrap/css/bootstrap.css" />
         <link rel="stylesheet" type="text/css" href="public/css/south-street/jquery-ui.css" />
         <link rel="stylesheet" type="text/css" href="public/css/appStyle.css" />
          <link rel="stylesheet" type="text/css" href="public/css/anytimec.css" />
            
         <script type="text/javascript" src="public/js/jquery.min.js"></script>
         <script type="text/javascript" src="public/js/jquery_ui.js"></script>
         <script type="text/javascript" src="public/js/appJS.js"></script>
         <script type="text/javascript" src="public/js/anytimec.js"></script>
         <script type="text/javascript" src="public/js/anytimetz.js"></script>
         <script type="text/javascript">
             $(function(){
                 $('#searchForm').submit(function(event){
                     event.preventDefault();
                    
                     $.post("SearchPublicRounds", $("#searchForm").serialize(), function(){
                          $.post("roundsResult.jsp", function(data){
                                $("#activity").html(data);
                            });                       
                    });
                 });
                 
                 
                 $("#joinToRoundButton").click(function(){
                     $.post("RegisterRequest", {idRound : $("#idRound").val()}, function(){
                         $("#joinToRoundButton").attr("disabled",true);
                     })
                 })
                 
                 <%List<Request> requestsApp2 = (List<Request>)request.getSession().getAttribute("requestsApp");
                for(Request r: requestsApp2){%>
                        $( "#profile-"+<% out.print(r.getRound().getUser().getIdUser()); %> ).dialog({
                    modal: true,
                    width: 600,
                    autoOpen: false
                });
                <% }               
               %>
                 
             });
             
             function cambiarEstado(id){
                $.post("ReadNotification", {idNotification: id}, function(){
                    window.location.href = "Home";
                });
                
  ;           }
            function show(id){
                $( "#profile-"+id ).dialog("open");
            }
            
            function close(id){
                $( "#profile-"+id ).dialog("close");
            }
            
         </script>
    </head>
    <body>
        <div id="homeWrapper">
            
            <div class="navbar navbar-top">
                <div class="navbar-inner">
                 <div class="container">
                    <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                   
                    </a>
                    <a class="brand" href="#">YoTeLlevo.Com</a>
                    <div class="nav-collapse">
                        <ul class="nav">
                            <li><a href="ListOwnerRounds">Mis Rutas</a></li>
                            <li><a href="LogOut">Salir</a></li>
                        </ul>
                    </div><!--/.nav-collapse -->
                 </div>
                </div>
            </div>
            
           <div class="container-fluid">
                
           <div id="userProfileInfo" class="span3 well">
               <h3>Datos del Usuario</h3><br />
               
               <img src="public/images/default.png">
               <%
                    User user =  (User)request.getSession().getAttribute("user");
                    
               %>
               <br><br>
               <table>
                   <tr>
                       <td><strong>Nombre de Perfil:</strong></td>
                       <td><% out.print(user.getProfileName()); %></td>
                   </tr>
                   <tr>
                       <td><strong>Correo:</strong></td>
                       <td><% out.print(user.getEmail()); %></td>
                   </tr>
                   <tr>
                       <td><strong>Fecha de Nacimiento:</strong></td>
                       <td><% SimpleDateFormat formatoDelTexto = new SimpleDateFormat("yyyy-MM-dd"); out.print(formatoDelTexto.format(user.getBirthDate())); %></td>
                   </tr>
                   <tr>
                       <td><strong>Empresa:</strong></td>
                       <td><% out.print(user.getCompany()); %></td>
                   </tr>
               </table>
               <br />
               <a href="LoadUserData">Actualizar mi Perfil</a> <br/>
               <a href="DeleteUser">Eliminar mi Perfil</a>
           </div>
            
            
            
                <div id="searchRound" class="span11">
                <form method="post" id="searchForm">
                <table>
                    <tr>
                        <td><label class="">Origen:</label></td>
                        <td><input type="text" class="span3" id="origin-search" name="origin"/></td>
                        <td><label class="">Destino:</label></td>
                        <td><input type="text" class="span3" id="destiny-search" name="destiny"/></td>
                   
                        <td><label>Hora:</label></td>
                        <td><div class=""><input type="text" id="hour1" class="span1" name="hour" /></div></td>
                        <td colspan="2" ><input type="submit" class="btn" value="Buscar"/></td>
                    </tr>
                    
                </table>
                </form>
                
                <hr>
            </div>
                
                
                <div id="activity" class="span8">
                    <% List<Notification> notifications = (List<Notification>)request.getSession().getAttribute("notifications"); %>
                    <h1>Notificaciones</h1>
                    <% if(notifications!=null){ %>
                    
                        <% for(Notification notification : notifications)
                        { %>
                        <div class='well' style="background-color:green" onmouseover="javascript:cambiarEstado(<% out.println(notification.getIdNotification()); %>);"><% out.println(notification.getMessage()); %></div>
                        <% }
                    }else{ %>
                    <div class="well"><h1 class="homeMessage">No existen notificaciones pendientes</h1></div>
                    <%}                       
                    %>
                    <% List<Request> requestsPenR = (List<Request>)request.getSession().getAttribute("requestsPenR");%>
                    <h1>Solicitudes recibidas</h1>
                    <%if(!requestsPenR.isEmpty()){ %>
                    
                        <% for(Request request1 : requestsPenR)
                        { %>
                        <div class='well'><% out.println(Constantes.getStringRequest(request1.getStatus())); %> del usuario: <% 
                                                                      out.println(request1.getUserBySender().getProfileName()); %> de la ronda con destino a: <% out.println(request1.getRound().getRoute().getDestiny()); %><a href="ApproveRequest?requestid=<% out.print(request1.getIdRequest()); %>">Aceptar</a>
                        <a href="RejectRequest?requestid="<% out.print(request1.getIdRequest()); %>>Rechazar</a></div>
                        <% }
                    }else{ %>
                    <div class="well"><h1 class="homeMessage">No existen solicitudes pendientes recibidas</h1></div>
                    <%}                       
                    %>
                     <% List<Request> requestsPen = (List<Request>)request.getSession().getAttribute("requestsPen"); %>
                     <h1>Solicitudes enviadas pendientes</h1>
                    <% if(!requestsPen.isEmpty()){ %>
                    
                        <% for(Request request1 : requestsPen)
                        { %>
                        <div class='well'><% out.println(Constantes.getStringRequest(request1.getStatus())); %> de la ronda con destino: <% 
                                                                      out.println(request1.getRound().getRoute().getDestiny()); %><a href="CancelRequest?requestid=<% out.print(request1.getIdRequest()); %>">Cancelar Solicitud</a>
                        </div>
                        <% }
                    }else{ %>
                    <div class="well"><h1 class="homeMessage">No existen solicitudes pendientes enviadas</h1></div>
                    <%}                       
                    %>
                    
                    <% List<Request> requestsApp = (List<Request>)request.getSession().getAttribute("requestsApp"); %>
                    <h1>Solicitudes enviadas aprovadas</h1>
                    <% if(!requestsApp.isEmpty()){ %>
                    
                        <% for(Request request1 : requestsApp)
                        { %>
                        <div class='well'><% out.println(Constantes.getStringRequest(request1.getStatus())); %> de la ronda con destino: <% 
                                                                                                                    out.println(request1.getRound().getRoute().getDestiny()); %> del usuario: <a href="#" onclick="javascript:show(<% out.println(request1.getRound().getUser().getIdUser()); %>);"><% out.println(request1.getRound().getUser().getProfileName()); %> </a><a href="CancelRequest?requestid=<% out.print(request1.getIdRequest()); %>">Cancelar Solicitud</a>
                        <div id="profile-<%out.print(request1.getRound().getUser().getIdUser()); %>">
                            <% User userList = request1.getRound().getUser(); 
                            double rate = 0; 
                            for(Rating rating: userList.getRatingsForOwner()){
                                rate += rating.getRating();
                            }
                            %>
                            <form class="well span5" >
                                <table>
                                    <tr>
                                        <td><label>Nombre: </label></td>
                                        <td><input class="span3" name="name" id="name" type="text" value="<% out.print(request1.getRound().getUser().getName() ); %>" disabled="disabled"></td>
                                    </tr>
                                    <tr>
                                        <td><label>Sexo: </label></td>
                                        <td><input type="radio" id="male" name="gender" value="male" <% if(request1.getRound().getUser().getGender().contentEquals("male")) out.println("checked"); %>  disabled="disabled"/> Hombre<input type="radio" id="female" name="gender" value="female" <% if(request1.getRound().getUser().getGender().compareTo("female")==0) out.println("checked"); %> disabled="disabled"/> Mujer</td>
                                    </tr>
                                    <tr>
                                        <td><label>Correo: </label></td>
                                        <td><input class="span3" name="email" type="text" value="<% out.print(request1.getRound().getUser().getEmail() ); %>" disabled="disabled"></td>
                                    </tr>
                                    <tr>
                                        <td><label>Empresa: </label></td>
                                        <td><input class="span3" name="company" type="text" value="<% out.print(request1.getRound().getUser().getCompany() ); %>" disabled="disabled"></td>
                                    </tr>
                                    <tr>
                                        <td>Valoracion </td>
                                        <td><% out.print(rate/userList.getRatingsForOwner().size()); %></td>
                                    </tr>
                                </table>
                            </form>
                        </div>
                        </div>
                        <% }
                    }else{ %>
                    <div class="well"><h1 class="homeMessage">No existen solicitudes aprovadas enviadas</h1></div>
                    <%}                       
                    %>
                </div>
                
            </div> <!-- Final de .container-->
            
    
            
        </div><!-- Final del contenedor principal-->
    </body>
</html>
